/** 
 * 项目名:extjs
 * 文件名:UserServiceImpl.java 
 * 包名:com.spring.extjs.service.impl 
 * 创建日期:2015年1月30日下午6:04:12 
 * 版权(c): 
 * 
*/  
  
package com.spring.extjs.service.impl;  

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.spring.extjs.dao.IUserDAO;
import com.spring.extjs.model.TUser;
import com.spring.extjs.pageModel.UserVO;
import com.spring.extjs.service.IUserService;
 
@Service
public class UserServiceImpl implements IUserService {

	@Autowired
	private IUserDAO userDAO;
	
	@Override
	public int insertUser(TUser user) {
		//需要根据user的id来判断是新增还是修改
		
		return userDAO.insertUser(user);
	}

	@Override
	public List<UserVO> userList() {
		
		List<TUser> list = userDAO.userList();
		
		List<UserVO> userList = new ArrayList<UserVO>();
		if (list != null && list.size() > 0) {
			for (TUser tUser : list) {
				UserVO user = new UserVO();
				BeanUtils.copyProperties(tUser, user);
				userList.add(user);
			}
		}
		return userList;
	}

	@Override
	public int modifyUser(TUser user) {
		
		return userDAO.modifyUser(user);
	}

	@Override
	public int deleteUsers(String userIds) {
		List<Integer> list = new ArrayList<Integer>();
		
		String[] arr = userIds.split(",");
		for (String str : arr) {
			list.add(Integer.parseInt(str));
		}
		return userDAO.deleteUserLogically(list);
	}

}
  